home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / demosrc / timesrc / mtmplay.asm < prev    next >
Encoding:
Assembly Source File  |  1994-02-24  |  13.3 KB  |  493 lines

  1.         .386p
  2. code32  segment para public use32
  3.         assume cs:code32, ds:code32
  4.  
  5. include pmode.inc
  6.  
  7. public  _mtm_voicebase, _mtm_voicenum, _mtm_playing, _mtm_ramtype
  8.  
  9. public  _mtmp_init, _mtmp_uninit, _mtmp_setmuz, _mtmp_playmuz, _mtmp_stopmuz
  10. public  _mtmp_phademuz
  11.  
  12. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  13. ; DATA
  14. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  15. align 4
  16. muzbaseptr      dd      ?               ; base ptr of muzik file
  17. insbaseptr      dd      ?               ; base ptr of instrument data
  18. ordbaseptr      dd      ?               ; base ptr of order list
  19. trkbaseptr      dd      ?               ; base ptr of track data
  20. patbaseptr      dd      ?               ; base ptr of pattern data
  21.  
  22. voicetrkptr     dd      16 dup(?)       ; ptr to track for each voice
  23. voicepanloc     db      16 dup(?)       ; pan locs for voices
  24. voicevol        db      16 dup(?)       ; voice volumes
  25.  
  26. soundcarddata   dd      ?               ; ptr to soundcard data structure
  27.  
  28. setmuzl1jtbl    dd    setmuzl1f1,setmuzl1f2,setmuzl1f3,setmuzl1f4,setmuzl1f5
  29.  
  30. realfreqtbl     dw      2166, 2294, 2431, 2573, 2728, 2891, 3063, 3245, 3438, 3642, 3859, 4088             ;2112, 2237, 2370, 2509, 2660, 2819, 2986, 3164, 3352, 3551, 3763, 3986
  31.                 dw      4332, 4589, 4862, 5147, 5457, 5782, 6126, 6490, 6876, 7285, 7718, 8177             ;4224, 4475, 4741, 5019, 5321, 5638, 5973, 6328, 6704, 7103, 7526, 7973
  32.                 dw      8664, 9179, 9725, 10294, 10915, 11565, 12252, 12981, 13752, 14571, 15437, 16355    ;8448, 8950, 9482, 10038, 10643, 11276, 11947, 12657, 13409, 14207, 15052, 15947
  33.                 dw      17328, 18358, 19450, 20589, 21831, 23130, 24505, 25962, 27505, 29142, 30874, 32710 ;16896, 17900, 18965, 20076, 21287, 22553, 23894, 25315, 26819, 28415, 30105, 31895
  34.                 dw      34656, 36716, 38900, 41179, 43663, 46260, 49011, 51925, 55010, 58284, 61749, 65421 ;33792, 35801, 37930, 40152, 42575, 45107, 47789, 50630, 53638, 56831, 60210, 63790
  35. freqtbl         dw      5*12 dup(?)
  36.  
  37. _mtm_voicebase  db      0               ; base voice of play
  38. _mtm_voicenum   db      16              ; number of voices to play
  39. _mtm_playing    db      ?               ; 1=muzik playing, 0=not
  40. _mtm_ramtype    db      ?               ; 1=ram on card, 0=system ram
  41. installed       db      0               ; 1=mtm player installed, 0=not
  42.  
  43. mtmtempo        db      ?               ; current tempo
  44. mtmtempocntr    db      ?               ; tempo counter
  45. mtmord          db      ?               ; current order playing
  46. mtmlastord      db      ?               ; last order to play in MTM module
  47. mtmrowstogo     db      ?               ; rows to go in current pattern
  48. mtmvolfactor    db      ?               ; volume scale factor
  49. mtmphading      db      ?               ; 1=muzik phading out, 0=not
  50. mtmphadespeed   db      ?               ; ticks to skip between phades
  51. mtmphadecntr    db      ?               ; phade tick counter
  52.  
  53. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  54. ; CODE
  55. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  56.  
  57. include low_data.m
  58.  
  59. ;═════════════════════════════════════════════════════════════════════════════
  60. mtmp:
  61.         cmp mtmphading,0
  62.         je short mtmpf2
  63.         mov al,mtmphadecntr
  64.         sub al,1
  65.         jnc short mtmpf3
  66.         mov bl,mtmvolfactor
  67.         sub bl,1
  68.         jnc short mtmpf4
  69.         call _mtmp_stopmuz
  70.         ret
  71. mtmpf4:
  72.         mov mtmvolfactor,bl
  73.         movzx ebp,_mtm_voicenum
  74.         sub ebp,1
  75.         jc short mtmpl2d
  76. mtmpl2:
  77.         mov al,voicevol[ebp]
  78.         mul bl
  79. ;       shr al,4
  80.         or _low_vccmnd[ebp],1
  81.         mov _low_vcvol[ebp],al
  82.         sub ebp,1
  83.         jnc mtmpl2
  84. mtmpl2d:
  85.         mov al,mtmphadespeed
  86. mtmpf3:
  87.         mov mtmphadecntr,al
  88. mtmpf2:
  89.  
  90.         mov al,mtmtempocntr
  91.         dec al
  92.         jnz mtmpf0
  93.         mov al,mtmrowstogo
  94.         dec al
  95.         jnz short mtmpf1
  96.  
  97.         movzx eax,mtmord
  98.         inc al
  99.         cmp al,mtmlastord
  100.         jbe short $+4
  101.         xor al,al
  102.         mov mtmord,al
  103.         mov ebx,ordbaseptr
  104.         mov al,[ebx+eax]
  105.         lea eax,[eax*8]
  106.         mov ebx,patbaseptr
  107.         lea ebx,[ebx+eax*8]
  108.         mov edx,trkbaseptr
  109.         movzx ecx,_mtm_voicenum
  110.         sub ecx,1
  111.         jc mtmpl0d
  112. mtmpl0:
  113.         movzx eax,word ptr [ebx+ecx*2]
  114.         or eax,eax
  115.         jz short mtmpl0c
  116.         lea eax,[eax*2+eax-3]
  117.         shl eax,6
  118.         add eax,edx
  119. mtmpl0c:
  120.         mov voicetrkptr[ecx*4],eax
  121.         sub ecx,1
  122.         jnc mtmpl0
  123. mtmpl0d:
  124.  
  125.         mov al,64
  126. mtmpf1:
  127.         mov mtmrowstogo,al
  128.  
  129.         movzx ebp,_mtm_voicenum
  130.         sub ebp,1
  131.         jc mtmpl1d
  132. mtmpl1:
  133.         mov edi,voicetrkptr[ebp*4]
  134.         or edi,edi
  135.         jz mtmpl1c
  136.         movzx eax,byte ptr [edi]
  137.         or eax,eax
  138.         jz short mtmpl1f0
  139.         mov ax,freqtbl[eax*2-2]
  140.         mov _low_vcfreq[ebp*2],ax
  141.         mov al,voicepanloc[ebp]
  142.         mov _low_vcpan[ebp],al
  143.         or _low_vccmnd[ebp],8
  144.         movzx ebx,byte ptr [edi+1]
  145.         imul ebx,37
  146.         add ebx,insbaseptr
  147.         mov al,[ebx+35]
  148.         mov voicevol[ebp],al
  149.         shl al,4
  150.         mov _low_vcvol[ebp],al
  151.         mov al,[ebx+12]
  152.         mov _low_vccntrl[ebp],al
  153.         mov eax,[ebx]
  154.         mov _low_vcsbeg[ebp*4],eax
  155.         mov eax,[ebx+4]
  156.         mov _low_vclbeg[ebp*4],eax
  157.         mov eax,[ebx+8]
  158.         mov _low_vclend[ebp*4],eax
  159. mtmpl1f0:
  160.         mov al,[edi+2]
  161.         cmp al,1
  162.         jb short mtmpl1c2
  163.         je short mtmpl1f1
  164.         test al,80h
  165.         jz short mtmpl1f2
  166.         test al,40h
  167.         jnz short mtmpl1f4
  168.         and al,0fh
  169.         mov voicevol[ebp],al
  170.         shl al,4                ;
  171.         mov _low_vcvol[ebp],al
  172.         or _low_vccmnd[ebp],1
  173.         jmp short mtmpl1c2
  174. mtmpl1f4:
  175.         and al,3fh
  176.         mov mtmtempo,al
  177.         jmp short mtmpl1c2
  178. mtmpl1f2:
  179.         test al,20h
  180.         jz short mtmpl1f3
  181.         and al,0fh
  182.         mov voicepanloc[ebp],al
  183.         mov _low_vcpan[ebp],al
  184.         or _low_vccmnd[ebp],2
  185.         jmp short mtmpl1c2
  186. mtmpl1f3:
  187.         and al,1fh
  188.         dec al
  189.         mov mtmord,al
  190. mtmpl1f1:
  191.         mov mtmrowstogo,1
  192. mtmpl1c2:
  193.         test _low_vccmnd[ebp],9
  194.         jz short mtmpl1f5
  195.         mov al,_low_vcvol[ebp]
  196.         mul mtmvolfactor
  197.         shr eax,4
  198.         mov _low_vcvol[ebp],al
  199. mtmpl1f5:
  200.         add edi,3
  201.         mov voicetrkptr[ebp*4],edi
  202. mtmpl1c:
  203.         sub ebp,1
  204.         jnc mtmpl1
  205. mtmpl1d:
  206.  
  207.         mov al,mtmtempo
  208. mtmpf0:
  209.         mov mtmtempocntr,al
  210.  
  211.         ret
  212.  
  213. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  214. ; Initialize MTM player
  215. ; In:
  216. ;   AH - number of voices (1-16)
  217. ;   BX - mixing rate (8000-44100)
  218. ;   ESI -> soundcard data structure
  219. ; Notes:
  220. ;   _low_port, _low_irq, and _low_dma must all be set before calling.
  221. ;   Allocates low memory.
  222. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  223. _mtmp_init:
  224.         call _mtmp_uninit
  225.         mov installed,1
  226.         push eax ebx
  227.  
  228.         mov soundcarddata,esi
  229.         mov ebx,_lomembase
  230.         mov _low_bufptr,ebx
  231.         mov al,[esi+4*9]
  232.         and al,1
  233.         mov _mtm_ramtype,al
  234.         mov _mtm_playing,0
  235.         mov _low_rout,offset _ret
  236.  
  237.         mov al,56
  238.         mov bx,[esp]
  239.         call _sound_init
  240.         mov eax,_low_buf
  241.         add _lomembase,eax
  242.  
  243.         mov ebx,(12*5-1)*2
  244. initl0:
  245.         movzx eax,realfreqtbl[ebx]
  246.         call _low_get_freq
  247.         mov freqtbl[ebx],ax
  248.         sub ebx,2
  249.         jnc initl0
  250.  
  251.         pop ebx eax
  252.         ret
  253.  
  254. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  255. ; Uninitialize MTM player
  256. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  257. _mtmp_uninit:
  258.         cmp installed,0
  259.         je _ret
  260.         mov installed,0
  261.         call _mtmp_stopmuz
  262.         call _low_uninit
  263.         ret
  264.  
  265. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  266. ; Set up muzik for play
  267. ; In:
  268. ;   EDX -> MTM module
  269. ; Out:
  270. ;   EAX - number of bytes to keep of module
  271. ; Notes:
  272. ;   Music data is altered, so if needs to be set up again, must reload it.
  273. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  274. _mtmp_setmuz:
  275.         pushad
  276.  
  277.         mov muzbaseptr,edx
  278.         mov al,[edx+27]
  279.         mov mtmlastord,al
  280.         lea edi,[edx+66]
  281.         mov insbaseptr,edi
  282.         movzx esi,byte ptr [edx+30]
  283.         imul esi,37
  284.         add esi,edi
  285.         mov ordbaseptr,esi
  286.         add esi,128
  287.         mov trkbaseptr,esi
  288.         movzx eax,word ptr [edx+24]
  289.         lea eax,[eax*2+eax]
  290.         shl eax,6
  291.         add esi,eax
  292.         mov patbaseptr,esi
  293.         movzx eax,byte ptr [edx+26]
  294.         shl eax,6
  295.         lea esi,[esi+eax+64]
  296.         movzx ebx,word ptr [edx+28]
  297.         add ebx,esi
  298.  
  299.         push ebx
  300.         mov al,[edx+30]
  301.         mov edx,ebx
  302.         mov ebp,offset _ret
  303.         cmp _mtm_ramtype,0
  304.         je short setmuzl0
  305.         xor ebx,ebx
  306.         mov ebp,_low_put_data
  307. setmuzl0:
  308.         mov ecx,[edi+22]
  309.         jecxz setmuzl0c
  310.         lea esi,[ecx-1]
  311. setmuzl0l0:
  312.         xor byte ptr [edx+esi],80h
  313.         sub esi,1
  314.         jnc setmuzl0l0
  315.         mov esi,[edi+30]
  316.         xor ah,ah
  317.         cmp esi,2
  318.         jbe short setmuzl0f0
  319.         mov ah,8
  320.         mov ecx,esi
  321. setmuzl0f0:
  322.         mov [edi+12],ah
  323.         call ebp
  324.         mov [edi],ebx
  325.         lea ecx,[ebx+ecx-2] ; -1]
  326.         mov [edi+8],ecx
  327.         mov ecx,[edi+26]
  328.         add ecx,ebx
  329.         mov [edi+4],ecx
  330.         mov ah,[edi+35]
  331.         sub ah,1
  332.         adc ah,0
  333.         shr ah,2
  334.         mov [edi+35],ah
  335.         mov ecx,[edi+22]
  336.         add ebx,ecx
  337.         add edx,ecx
  338. setmuzl0c:
  339.         add edi,37
  340.         dec al
  341.         jnz setmuzl0
  342.         pop ebx
  343.         cmp _mtm_ramtype,0
  344.         je short $+4
  345.         mov edx,ebx
  346.         sub edx,muzbaseptr
  347.         mov [esp+28],edx
  348.  
  349.         mov edi,trkbaseptr
  350.         mov ecx,muzbaseptr
  351.         movzx ecx,word ptr [ecx+24]
  352.         shl ecx,6
  353. setmuzl1:
  354.     xor ebx,ebx
  355.     movzx eax,byte ptr [edi+1]
  356.     and al,0fh
  357.     sub al,0bh
  358.     jc short setmuzl1f0
  359.     mov bl,[edi+2]
  360.     jmp setmuzl1jtbl[eax*4]
  361. setmuzl1f1:
  362.     and bl,1fh
  363.     or bl,40h
  364.     jmp short setmuzl1f0
  365. setmuzl1f2:
  366.     sub bl,1
  367.     adc bl,0
  368.     shr bl,2
  369.     or bl,80h
  370.     jmp short setmuzl1f0
  371. setmuzl1f3:
  372.     mov bl,1
  373.     jmp short setmuzl1f0
  374. setmuzl1f4:
  375.     mov bh,bl
  376.     and bl,0f0h
  377.     cmp bl,80h
  378.     mov bl,0
  379.     jne short setmuzl1f0
  380.     mov bl,bh
  381.     and bl,0fh
  382.     or bl,60h
  383.         jmp short setmuzl1f0
  384. setmuzl1f5:
  385.     shl ebx,2
  386.     mov eax,60*56
  387.     xor edx,edx
  388.     div ebx
  389.         or al,0c0h
  390.     mov bl,al
  391. setmuzl1f0:
  392.     mov [edi+2],bl
  393.         mov ax,[edi]
  394.         ror ax,2
  395.         and al,3fh
  396.         shr ah,2
  397.         sub ah,1
  398.         adc ah,0
  399.         mov [edi],ax
  400.         add edi,3
  401.         loop setmuzl1
  402.  
  403.         mov ebp,muzbaseptr
  404.         lea edi,[ebp+34]
  405.         movzx edx,_mtm_voicebase
  406.         lea esi,[edi+edx]
  407.         movzx ebx,_mtm_voicenum
  408.         mov ecx,ebx
  409.         rep movsb
  410.         movzx ebp,byte ptr [ebp+26]
  411.         mov edi,patbaseptr
  412.         shl edx,1
  413.         xor eax,eax
  414. setmuzl2:
  415.         lea esi,[edi+edx]
  416.         mov ecx,ebx
  417.         rep movsw
  418.         mov cl,32
  419.         sub ecx,ebx
  420.         rep stosw
  421.         sub ebp,1
  422.         jnc setmuzl2
  423.  
  424.         popad
  425.         ret
  426.  
  427. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  428. ; Start muzik playback
  429. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  430. _mtmp_playmuz:
  431.         call _mtmp_stopmuz
  432.         push eax ebx
  433.         mov ebx,muzbaseptr
  434.         mov eax,[ebx+34+0]
  435.         mov dword ptr voicepanloc[0],eax
  436.         mov eax,[ebx+34+4]
  437.         mov dword ptr voicepanloc[4],eax
  438.         mov eax,[ebx+34+8]
  439.         mov dword ptr voicepanloc[8],eax
  440.         mov eax,[ebx+34+12]
  441.         mov dword ptr voicepanloc[12],eax
  442.         xor eax,eax
  443.         mov dword ptr voicevol[0],eax
  444.         mov dword ptr voicevol[4],eax
  445.         mov dword ptr voicevol[8],eax
  446.         mov dword ptr voicevol[12],eax
  447.         mov mtmphading,al
  448.         mov al,1
  449.         mov _mtm_playing,al
  450.         mov mtmrowstogo,al
  451.         mov mtmtempocntr,al
  452.         mov mtmvolfactor,10h
  453.         mov mtmtempo,7
  454.         mov mtmord,-1
  455.         mov _low_rout,offset mtmp
  456.         pop ebx eax
  457.         ret
  458.  
  459. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  460. ; Stop muzik playback
  461. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  462. _mtmp_stopmuz:
  463.         cmp _mtm_playing,0
  464.         je _ret
  465.         push eax
  466.         mov _low_rout,offset _ret
  467.         mov _mtm_playing,0
  468.         movzx eax,_mtm_voicenum
  469. stopmuzl0:
  470.         sub al,1
  471.         jc short stopmuzl0d
  472.         mov _low_vcvol[eax],0
  473.         mov _low_vccmnd[eax],1
  474.         jmp stopmuzl0
  475. stopmuzl0d:
  476.         pop eax
  477.         ret
  478.  
  479. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  480. ; Set muzik to phade out
  481. ; In:
  482. ;   AL - speed to phade at (ticks to skip between phades (1/56th sec))
  483. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  484. _mtmp_phademuz:
  485.         mov mtmphading,1
  486.         mov mtmphadespeed,al
  487.         mov mtmphadecntr,0
  488.         ret
  489.  
  490. code32  ends
  491.         end
  492.  
  493.